home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / elm / elm2.3pl11 / src / quit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-04-28  |  5.3 KB  |  177 lines

  1.  
  2. static char rcsid[] = "@(#)$Id: quit.c,v 4.1 90/04/28 22:43:44 syd Exp $";
  3.  
  4. /*******************************************************************************
  5.  *  The Elm Mail System  -  $Revision: 4.1 $   $State: Exp $
  6.  *
  7.  *             Copyright (c) 1986, 1987 Dave Taylor
  8.  *             Copyright (c) 1988, 1989, 1990 USENET Community Trust
  9.  *******************************************************************************
  10.  * Bug reports, patches, comments, suggestions should be sent to:
  11.  *
  12.  *    Syd Weinstein, Elm Coordinator
  13.  *    elm@DSI.COM            dsinc!elm
  14.  *
  15.  *******************************************************************************
  16.  * $Log:    quit.c,v $
  17.  * Revision 4.1  90/04/28  22:43:44  syd
  18.  * checkin of Elm 2.3 as of Release PL0
  19.  * 
  20.  *
  21.  ******************************************************************************/
  22.  
  23. /** quit: leave the current folder and quit the program.
  24.   
  25. **/
  26.  
  27. #include "headers.h"
  28. #include <errno.h>
  29.  
  30. extern int errno;        /* system error number on failure */
  31.  
  32. long bytes();
  33.  
  34. quit(prompt)
  35. int prompt;
  36. {
  37.     /* a wonderfully short routine!! */
  38.  
  39.     if (leave_mbox(FALSE, TRUE, prompt) == -1)
  40.       /* new mail - leave not done - can't change to another file yet
  41.        * check for change in mailfile_size in main() will do the work
  42.        * of calling newmbox to add in the new messages to the current
  43.        * file and fix the sorting sequence that leave_mbox may have
  44.        * changed for its own purposes */
  45.       return;
  46.  
  47.     leave();
  48. }
  49.  
  50. int
  51. resync()
  52. {
  53.     /** Resync on the current folder. Leave current and read it back in.
  54.         Return indicates whether a redraw of the screen is needed.
  55.      **/
  56.  
  57.       if(leave_mbox(TRUE, FALSE, TRUE) ==-1)
  58.         /* new mail - leave not done - can't change to another file yet
  59.          * check for change in mailfile_size in main() will do the work
  60.          * of calling newmbox to add in the new messages to the current
  61.          * file and fix the sorting sequence that leave_mbox may have
  62.          * changed for its own purposes */
  63.         return(FALSE);
  64.  
  65.       if ((errno = can_access(cur_folder, READ_ACCESS)) != 0) {
  66.         dprint(1, (debugfile,
  67.           "Error: given file %s as folder - unreadable (%s)!\n", 
  68.           cur_folder, error_name(errno)));
  69.         fprintf(stderr,"Can't open folder '%s' for reading!\n", cur_folder);
  70.         leave();
  71.         }
  72.  
  73.       newmbox(cur_folder, FALSE);
  74.       return(TRUE);
  75. }
  76.  
  77. change_file()
  78. {
  79.       /* Prompt user for name of folder to change to.
  80.        * If all okay with that folder, leave the current folder.
  81.        * If leave goes okay (i.e. no new messages in current folder),
  82.        * change to the folder that the user specified.
  83.        *
  84.        * Return value indicates whether a redraw is needed.
  85.        */
  86.  
  87.       int redraw = FALSE;
  88.       char newfile[SLEN];
  89.       static char helpmsg[LONG_STRING];
  90.  
  91.       char    *nameof();
  92.  
  93.  
  94.       /* get new file name */
  95.  
  96.       MoveCursor(LINES-3, 30);
  97.       CleartoEOS();
  98.       PutLine0(LINES-3, 38, "(Use '?' for help/to list your folders.)");
  99.       PutLine0(LINES-2,0,"Change to which folder: ");
  100.       while(1) {
  101.         newfile[0] = '\0';
  102.         (void) optionally_enter(newfile, LINES-2, 24, FALSE, FALSE);
  103.         clear_error();
  104.  
  105.         if(*newfile == '\0') {    /* if user didn't enter a file name */
  106.           MoveCursor(LINES-3, 30);    /* abort changing file process */
  107.           CleartoEOS();
  108.           return(redraw);
  109.  
  110.         } else if (strcmp(newfile, "?") == 0) {
  111.  
  112.           /* user wants to list folders */
  113.           if(!*helpmsg) {    /* format helpmsg if not yet done */
  114.  
  115.         strcpy(helpmsg,
  116.           "\n\r\n\rEnter: <nothing> to not change to a new folder,");
  117.         strcat(helpmsg,
  118.           "\n\r       '!' to change to your incoming mailbox (");
  119.         strcat(helpmsg, defaultfile);
  120.         strcat(helpmsg,
  121.           ")\n\r       '>' to change to your \"received\" folder (");
  122.         strcat(helpmsg, nameof(recvd_mail));
  123.         strcat(helpmsg,
  124.           ")\n\r       '<' to change to your \"sent\" folder (");
  125.         strcat(helpmsg, nameof(sent_mail));
  126.         strcat(helpmsg, ")\n\r       or a filename");
  127.         strcat(helpmsg,
  128.           " (leading '=' denotes your folder directory ");
  129.         strcat(helpmsg, folders);
  130.         strcat(helpmsg, ").\n\r");
  131.           }
  132.           list_folders(4, helpmsg);
  133.           PutLine0(LINES-2,0,"Change to which folder: ");    /* reprompt */
  134.           redraw = TRUE;        /* we'll need to clean the screen */
  135.  
  136.         } else {
  137.  
  138.           /* user entered a file name - expand it */
  139.           if (! expand_filename(newfile, TRUE))
  140.         continue;    /* prompt again */
  141.  
  142.           /* don't accept the same file as the current */
  143.           if (strcmp(newfile, cur_folder) == 0) {
  144.         error("Already reading that folder!");
  145.         continue;    /* prompt again */
  146.           }
  147.  
  148.           /* Make sure this is a file the user can open, unless it's the
  149.            * default mailfile, which is openable even if empty */
  150.           if ((errno = can_access(newfile, READ_ACCESS)) != 0 ) {
  151.         if (strcmp(newfile, defaultfile) != 0 || errno != ENOENT) {
  152.           error1("Can't open folder '%s' for reading!", newfile);
  153.           continue;     /* prompt again */
  154.         }
  155.           }
  156.           break;    /* exit loop - we got the name of a good file */
  157.         }
  158.       }
  159.  
  160.       /* All's clear with the new file to go ahead and leave the current. */
  161.       MoveCursor(LINES-3, 30);
  162.       CleartoEOS();
  163.  
  164.       if(leave_mbox(FALSE, FALSE, TRUE) ==-1) {
  165.         /* new mail - leave not done - can't change to another file yet
  166.          * check for change in mailfile_size in main() will do the work
  167.          * of calling newmbox to add in the new messages to the current
  168.          * file and fix the sorting sequence that leave_mbox may have
  169.          * changed for its own purposes */
  170.         return(redraw);
  171.       }
  172.  
  173.       redraw = 1;
  174.       newmbox(newfile, FALSE);
  175.       return(redraw);
  176. }
  177.